package tc.de.krawallmann.gravoblocks.game.model;

/**
 * A TetrisTile is a composite of TetrisBlocks.
 * @author KrawallMann
 * @version 1.1
 */
public class TetrisTile {
	/** The rotation. */
	private int rotation;

	/** The shape. */
	private TileShape shape;

	/** The x position. */
	private int xPosition;

	/** The y position. */
	private int yPosition;

	/**
	 * Instantiates a new tile.
	 * 
	 * @deprecated For deserialization only!
	 */
	@Deprecated
	public TetrisTile() {
		super();
	}

	/**
	 * Instantiates a new tile.
	 * 
	 * @param shape
	 *            the shape
	 * @param rotation
	 *            the rotation
	 * @param relativePositions
	 *            the relative positions
	 */
	public TetrisTile(final TileShape shape, final int rotation) {
		super();
		this.shape = shape;
		this.rotation = rotation;
	}

	/**
	 * Copy.
	 * 
	 * @return the tetris tile
	 */
	public TetrisTile copy() {
		final TetrisTile ret = new TetrisTile(shape, rotation);
		ret.setXPosition(xPosition);
		ret.setYPosition(yPosition);
		return ret;
	}

	/**
	 * Gets the color.
	 * 
	 * @return the color
	 */
	public BlockColor getColor() {
		BlockColor ret;
		switch (shape) {
			case TYPE_I: {
				ret = BlockColor.CYAN;
				break;
			}
			case TYPE_J: {
				ret = BlockColor.ORANGE;
				break;
			}
			case TYPE_L: {
				ret = BlockColor.BLUE;
				break;
			}
			case TYPE_O: {
				ret = BlockColor.YELLOW;
				break;
			}
			case TYPE_S: {
				ret = BlockColor.RED;
				break;
			}
			case TYPE_Z: {
				ret = BlockColor.GREEN;
				break;
			}
			case TYPE_T: {
				ret = BlockColor.PURPLE;
				break;
			}
			case TYPE_PLUS: {
				ret = BlockColor.BLUE;
				break;
			}
			case TYPE_U: {
				ret = BlockColor.RED;
				break;
			}
			case TYPE_V: {
				ret = BlockColor.YELLOW;
				break;
			}
			default: {
				ret = BlockColor.WHITE;
			}
		}
		return ret;
	}

	/**
	 * Gets the relative positions at the current rotation.
	 * 
	 * @return the relative positions at the current rotation
	 */
	public Point[] getCurrentRelativePositions() {
		return shape.getPositions(this.rotation);
	}

	/**
	 * Gets the relative positions at the given rotation.
	 * 
	 * @param rotation
	 *            the rotation
	 * @return the relative positions at the given rotation
	 */
	public Point[] getRelativePositions(final int rotation) {
		return shape.getPositions(rotation);
	}

	/**
	 * Gets the rotation.
	 * 
	 * @return the rotation
	 */
	public int getRotation() {
		return rotation;
	}

	/**
	 * Gets the shape.
	 * 
	 * @return the shape
	 */
	public TileShape getShape() {
		return shape;
	}

	/**
	 * Gets the tile count.
	 * 
	 * @return the tile count
	 */
	public int getTileCount() {
		return shape.getLength();
	}

	/**
	 * Gets the x position.
	 * 
	 * @return the x position
	 */
	public int getXPosition() {
		return xPosition;
	}

	/**
	 * Gets the y position.
	 * 
	 * @return the y position
	 */
	public int getYPosition() {
		return yPosition;
	}

	/**
	 * Sets the rotation.
	 * 
	 * @param rotation
	 *            the new rotation
	 */
	public void setRotation(final int rotation) {
		this.rotation = rotation;
	}

	/**
	 * Sets the shape.
	 * 
	 * @param shape
	 *            the new shape
	 * @deprecated For deserialization only!
	 */
	@Deprecated
	public void setShape(final TileShape shape) {
		this.shape = shape;
	}

	/**
	 * Sets the x position.
	 * 
	 * @param xPosition
	 *            the new x position
	 */
	public void setXPosition(final int xPosition) {
		this.xPosition = xPosition;
	}

	/**
	 * Sets the y position.
	 * 
	 * @param yPosition
	 *            the new y position
	 */
	public void setYPosition(final int yPosition) {
		this.yPosition = yPosition;
	}
}
